Alright now that I’ve introduced the course, I wanted to introduce you the tools that we'll be using.
Throughout this course I'm going to be using an IPython notebook. The IPython notebook is a part of the anaconda distribution that I recommended before.
IPython is an interactive computing interface for python that adds some extremely helpful tools to python. Let’s go ahead and get started with that.
We start the IPython Notebook from the command like by just typing in ipython notebook
. It has a lower level interface, IPython, but I won't be covering that in this course.
The IPython Notebook adds lots of helper commands, adds tab completion, general developer happiness tools to python.
An IPython notebook is made up of cells. There are various kinds of cells that I can set up from this top menu. Simply there are code cells that can be executed and text cells that can be styled.
Let's start with a simple command in this first cell.
In [1]:
from __future__ import print_function # python 3 support from python 2
In [2]:
print("Hello IPython")
You'll see that we can see the output of any command that we execute in thse cells. Now cells all share the same global environment. So if we set a variable in one, we can print it out in another.
In [3]:
x = 5
In [4]:
print(x)
We can also define functions in cells and access those in others. (use tab completion)
In [5]:
def square(input_var):
return input_var * input_var
you also saw right there that I can use tab completion to complete those variables. That's another handy thing about the IPython notebook. Tab completion.
We can also get access to certain shell commands like "ls" to list everything in the current directory.
In [6]:
square(x)
Out[6]:
In [7]:
ls
We also get access to some "magic commands". These commands are baked into IPython and provide us some really, really helpful ways of writing code without having to google things all the time.
For example, quickref
In [8]:
%quickref
Quickref brings up the quickreference for IPython, we can see all the commands that are made available to us.
Some of my favorites are the ? and %timeit
Here's a demonstration of the ? helper. Say I've imported a module, let's say datetime and I forgot the order of arguments when creating a new one.
In [9]:
from datetime import datetime
In [10]:
?datetime
All I have to do is put a question mark either before or after it and it will bring up the documentation for that specific module or function.
In [11]:
datetime?
In [12]:
?square
This is super handy and something you'll be seeing through out this course because I use it a lot when I'm working in IPython notebooks. Timeit is also useful because it allows for easy profiling.
In [13]:
%timeit square(x)
Now I will warn you, I’ve used IPython Notebooks and while they are great for rapid prototyping and sharing your scientific code or analysis they're not so great for writing production systems.
However the notebook interface allows you to save a .py file so that you may build on your basic prototype into a production system. There's a lot of functionality built in to the IPython notebook and you could make a whole course on it. Please feel free to ask questions on the message boards and I'll be sure to answer them as quickly as I can.
Now that I’ve introduced the basics of this tool we can start diving into the material.